

Vue.createApp({
    // 定义组件
    components:{
        "my-article": ARTICLE,
    },
    // 初始化
    setup(){
        // reactive定义变量运行存储
        // toRefs将数据返回
        const {
            reactive, toRefs
        } = Vue
        // 定义变量，即所需数据
        const state = reactive({
            users: {},
            articles: {},
            // 展示用户的下标
            showIndex: 0
        })
        get("/getFollow", function(data){
            state.users = data
            if (data.length != 0) {
                getArticlesByUserId(state, data[0].userId)
            }
        }, function(data) {
            console.log(data);
            console.log("myFollow error");
        })

        // 返回数据
        return {
            ...toRefs(state)
        }
    },
    methods:{
        // 通过接收子组件的信息设置showIndex
        setShowIndex(showIndex){
            this.showIndex = showIndex
            // 更新文章信息
            getArticlesByUserId(this, this.users[this.showIndex].userId)

        }
    }
    // 绑定app
}).mount("#myFollow")

function getArticlesByUserId(that, userId){
    get("/getArticlesByUserId/" + userId, function(data){
        that.articles = data
    })
}